package ubi.quando.App;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.osmdroid.util.GeoPoint;

public abstract class EventBase implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public static final String SerializeName = "Event";

	String mId;
	String mName;
	Date mDate;
	GeoPoint mDestination;
	String mDestName;
	String mCreatorId;
	Map<Contact, PickUpParticipant> mAwaiting;
	boolean mStarted;

	protected EventBase(GeoPoint dest, Date date, String creatorId) {
		mDestination = dest;
		mDate = date;
		mCreatorId = creatorId;
		mAwaiting = new HashMap<Contact, PickUpParticipant>();
		mStarted = false;
	}
	
	public void setStarted(boolean started) {
		this.mStarted = started;
	}
	
	public boolean isStarted() {
		return mStarted;
	}
	
	public void AddInvited(Contact contact, PickUpParticipant invited) {
		mAwaiting.put(contact, invited);
	}

	public void RemoveInvited(Contact invited) {
		mAwaiting.remove(invited);
	}

	public void ClearInvited() {
		mAwaiting.clear();
	}

	public Map<Contact, PickUpParticipant> getAwaiting() {
		return mAwaiting;
	}

	public Date GetDate() {
		return mDate;
	}

	public void SetDate(Date date) {
		mDate = date;
	}

	protected void writeObject(ObjectOutputStream out) throws IOException {
		out.writeObject(mName);
		out.writeObject(mId);
		out.writeObject(mDate);
		out.writeObject(mDestination);
		out.writeObject(mDestName);
		out.writeObject(mCreatorId);
	}

	protected void readObject(ObjectInputStream in) throws IOException,
			ClassNotFoundException {
		Object temp = in.readObject();
		if (temp != null) {
			mName = (String) temp;
		}
		temp = in.readObject();
		if (temp != null) {
			mId = (String) temp;
		}
		temp = in.readObject();
		if (temp != null) {
			mDate = (Date) temp;
		}
		temp = in.readObject();
		if (temp != null) {
			mDestination = (GeoPoint) temp;
		}
		temp = in.readObject();
		if (temp != null) {
			mDestName = (String) temp;
		}
		temp = in.readObject();
		if (temp != null) {
			mCreatorId = (String) temp;
		}
	}

	public GeoPoint GetDestination() {
		return mDestination;
	}

	public void SetDestination(GeoPoint loc) {
		mDestination = loc;
	}
	
	public String GetName() {
		return mName;
	}
	
	public void SetName(String name) {
		mName = name;
	}
	
	public void setId(String id) {
		mId = id;
	}
	
	public String getId() {
		return mId;
	}
	
	public void setDestName(String destName) {
		mDestName = destName;
	}
	
	public String getdestName() {
		return mDestName;
	}
	
	public abstract EventType getType();

	public Object getCreatorId() {
		return mCreatorId;
	}
	
	@Override
	public int hashCode() {
		return mId.hashCode();
	}
	
	@Override
	public boolean equals(Object o) {
		EventBase other = (EventBase) o;
		if (other.getId() == mId) {
			return true;
		}
		return false;
	}
	
	

}
